<template>
  <div id="storeManageDiyform">
    <c-title :hide="false" text="自定义表单"></c-title>
    <div class="list" >
      <div class="clis" style="margin-top: 0.75rem;" v-for="(item, index) in list" :key="index">
        <div class="top">
          <img src="https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2FstoreManagement%2Fdiyform3@2x.png" alt="" />
          <div class="title">{{ item.title }}</div>
        </div>
        <div class="bottom">
          <div class="btn" v-clipboard:copy="copyLink(item)" v-clipboard:success="onCopy">
            <img src="https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2FstoreManagement%2Fdiyform4@2x.png" alt="" />
            <div class="name">复制链接</div>
          </div>
          <div class="btn" @click="toEditFrom(item)">
            <img src="https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images/storeManagement/diyform6@2x.png" alt="" />
            <div class="name">填写表单</div>
          </div>
          <div class="btn" @click="toGoDetail(item.id)">
            <img src="https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2FstoreManagement%2Fdiyform5@2x.png" alt="" />
            <div class="name">查看数据</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { Toast } from "vant";
import { scrollMixin } from "utils/mixin";
export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      list: [],
      goods_link: "wwww.com",

      //more
      isLoadMore: true,
      page: 1,
      total_page: 0
    };
  },
  activated() {
    this.getData();
  },
  computed:{
    copyLink(item){
      return (item)=>{
        let mid = this.fun.getKeyByMid();
        return this.fun.getSiteRoot() + "/addons/yun_shop/?menu#/diyform/"+item.id+"?i=" + this.fun.getKeyByI() + "&mid=" + mid
      }
    },
  },
  methods: {
    toEditFrom(item){
      window.location.href = this.copyLink(item)
    },
    // 复制链接
    onCopy() {
      Toast({
        message: "复制成功",
        position: "bottom",
        duration: 5000
      });
    },
    toGoDetail(id) {
      this.$router.push(this.fun.getUrl("storeManageFormDetail",{form_id:id}));
    },
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      let json = {
        page: this.page
      };
      if (this.page >= this.total_page) {
        this.isLoadMore = false;
        return;
      } else {
        this.isLoading = true;
        this.page = this.page + 1;
        json.page = this.page;
        $http
          .get("plugin.diyform.api.diy-form.formList", json, "加载中")
          .then(response => {
            this.isLoadMore = true;
            if (response.result === 1) {
              this.list = this.list.concat(response.data.data);
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
              return;
            }
          })
          .catch(err => {
            console.log(err);
          });
      }
    },
    getData() {
      $http
        .post("plugin.diyform.api.diy-form.formList")
        .then(res => {
          if (res.result == 1) {
            this.list = res.data.data;
            this.isLoadMore = true;
            this.total_page = res.data.last_page;
            if (!this.total_page) {
              this.total_page = 0;
            }
          }
        })
        .catch(err => {
          console.log(err);
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.list {
  margin: 0.75rem 0.75rem;
  padding-bottom: 1rem;

  .clis {
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    background: #fff;
    border-radius: 0.5rem;

    .top {
      display: flex;
      align-items: center;

      img {
        width: 1.5rem;
        height: 1.5rem;
        border-radius: 50%;
        margin-right: 0.25rem;
      }

      .title {
        flex: 1;
        text-align: left;
      }
    }

    .bottom {
      display: flex;
      justify-content: space-around;
      align-items: center;
      margin-top: 0.75rem;

      .btn {
        display: flex;
        justify-content: center;
        flex-direction: column;
        align-items: center;

        .name {
          font-size: 0.75rem;
          color: #999;
          margin-top: 0.25rem;
        }

        img {
          width: 1.5rem;
          height: 1.5rem;
        }
      }
    }
  }
}
</style>